{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "08355c61",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2,winsound\n",
    "\n",
    "model = cv2.CascadeClassifier('model/face.xml')\n",
    "camera = cv2.VideoCapture(0)\n",
    "\n",
    "while True:\n",
    "    ok,image = camera.read()\n",
    "    if not ok:\n",
    "        print('未检测到摄像头')\n",
    "        break\n",
    "    objs = model.detectMultiScale(image,1.1,20) # 20 -> 投票\n",
    "    for x,y,w,h in objs:\n",
    "        cv2.rectangle(image,(x,y,w,h),(0,100,255),3) # 矩形\n",
    "    cv2.imshow('image',image)\n",
    "    # 结束部分\n",
    "    k = cv2.waitKey(10)\n",
    "    if k == 27:\n",
    "        cv2.destroyAllWindows()\n",
    "        camera.release()\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2bd16a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2,winsound\n",
    "\n",
    "model = cv2.CascadeClassifier('model/eye.xml')\n",
    "camera = cv2.VideoCapture(0)\n",
    "\n",
    "while True:\n",
    "    ok,image = camera.read()\n",
    "    if not ok:\n",
    "        print('未检测到摄像头')\n",
    "        break\n",
    "    objs = model.detectMultiScale(image,1.1,20) # 20 -> 投票\n",
    "    for x,y,w,h in objs:\n",
    "        cv2.rectangle(image,(x,y,w,h),(0,100,255),3) # 矩形\n",
    "    cv2.imshow('image',image)\n",
    "    if len(objs)<2: # eye.xml only\n",
    "        winsound.Beep(500,300) # eye.xml only\n",
    "    # 结束部分\n",
    "    k = cv2.waitKey(10)\n",
    "    if k == 27: # 27 -> Esc\n",
    "        cv2.destroyAllWindows()\n",
    "        camera.release()\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b5c5bea",
   "metadata": {},
   "source": [
    "object 东西，事务，目标，实体"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
